package com.lzx.adx.report.support.strategy.mpping;

import com.alibaba.fastjson.JSONObject;
import com.lzx.adx.report.bean.mapper.ReportMapper;
import com.lzx.adx.report.model.common.CommonReportRequest;
import com.lzx.adx.report.model.youyou.YouYouRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Slf4j
public class YoYoReportMappingStrategy extends AbstractReportParamsMapping{

    @Autowired
    private ReportMapper reportMapper;

    @Override
    public CommonReportRequest adapter(Map<String,Object> params) {
        String jsonString = JSONObject.toJSONString(params);
        log.info("YOYO互联的原始参数为{}",jsonString);
        YouYouRequest youYouRequest = JSONObject.parseObject(jsonString, YouYouRequest.class);

        CommonReportRequest commonReportRequest=new CommonReportRequest();
        BeanUtils.copyProperties(youYouRequest,commonReportRequest);
        commonReportRequest.setOaidSum(youYouRequest.getOaidMd5());
        commonReportRequest.setImeiSum(youYouRequest.getImeiMd5());
        commonReportRequest.setIdfaSum(youYouRequest.getIdfaMd5());
        commonReportRequest.setCallback(youYouRequest.getCallbackUrl());
        commonReportRequest.setTraceTime(youYouRequest.getTimestamp());
        log.info("YOYO互联的转化后的参数为{}",JSONObject.toJSONString(commonReportRequest));
        return commonReportRequest;

    }
}
